package cn.zbmao.web.services;

import cn.zbmao.web.util.dao.DaoFactory;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

public class HomeServices {

    /**
     *
     * @param user_id
     * @return
     * 查出该用户关注的所有地域，有的话，将地域经行拼接，以字符串形式返回，
     * 没有则返回“暂无”
     */
	public static String getUser_district(int user_id){
		List<Record> list= DaoFactory.getUserDao().getUser_district(user_id);
		if (list.isEmpty()) {
			return "暂无";
		}
//        将地域经行字符串拼接
		StringBuffer sb = new StringBuffer();
		sb.append("[");
		for (int i = 0; i < list.size(); i++) {
			if (i==0) {
				sb.append(list.get(i).getStr("name"));
			}else{
				sb.append(","+list.get(i).getStr("name"));
			}
		}
		sb.append("]");
		return sb.toString();
	}

    /**
     *
     * @param user_id
     * @return
     * 查询用户关注的所有关键字，并经行拼接，以字符串形式返回
     */
	public static String getUser_keyword(int user_id){
		List<Record> list= DaoFactory.getUserDao().getUser_key(user_id);
		if (list.isEmpty()) {
			return "暂无";
		}
//        关键字拼接
		StringBuffer sb = new StringBuffer();
		sb.append("[");
		for (int i = 0; i < list.size(); i++) {
			if (i==0) {
				sb.append(list.get(i).getStr("keyword"));
			}else{
				sb.append(","+list.get(i).getStr("keyword"));
			}
		}
		sb.append("]");
		return sb.toString();
	}
	
	public static List<Record> getUser_url(int user_id){
		List<Record> list= DaoFactory.getUserDao().getUser_url(user_id);
		if (list.isEmpty()) {
			list.add(new Record().set("url", "暂无"));
			return list;
		}
		return list;
	}
}
